package com.whpu.admin.controller;

import com.whpu.admin.service.AdminService;
import com.whpu.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by RiceBall on 2020/10/23 9:29
 */
@Controller
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @RequestMapping("/login")
    public String login(String username, String password, HttpSession session) {
        List<User> users = adminService.login(username, password);
        if (users != null && users.size() != 0) {
            session.setAttribute("USER", users.get(0));
            return "/admin/index";
        }
        return "redirect:/login.jsp";
    }

    @RequestMapping("/findAll")
    public String list() {
        return "redirect:/user/findAll";
    }
}
